package com.zmj.socket;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 *
 * @author zhangmj
 * @date 2018/9/24 10:41
 */
@Slf4j
public class ServerHandler implements Runnable{

    private Socket socket ;

    public ServerHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run(){
        InputStream ins = null;
        try {
            ins = socket.getInputStream();
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = ins.read(buffer)) > 0){
                log.info(new String(buffer,0,len));
            }
            OutputStream outs = socket.getOutputStream();
            outs.write("hello everybody!".getBytes());
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
